package config

import (
	"github.com/hwcer/cosgo/utils"
	"github.com/hwcer/yyds"
	"github.com/hwcer/yyds/options"
	"server/share/protoc"
)

const ModuleName = "config"

var mod *Module

func init() {
	mod = &Module{}
}

func New() *Module {
	return mod
}

var Data = &output{}

type output struct {
	protoc.Configs
}

type KV struct {
	K int32
	V int32
}

type Weight map[int32]int32 //id -->权重

type Module struct {
}

func (this *Module) Id() string {
	return ModuleName
}

func (this *Module) Init() (err error) {
	return utils.Assert(options.Initialize, this.Reload)
}
func (this *Module) Start() (err error) {
	return nil
}

func (this *Module) Close() (err error) {
	return nil
}

func (this *Module) Reload() (err error) {
	d := &output{}
	if err = yyds.Config.Reload(d, options.Options.Data); err != nil {
		return err
	}
	Data = d
	return nil
}

type HandleDefault struct {
}

func (this *HandleDefault) Handle(c *yyds.CS, d any) {

}
func (this *HandleDefault) Verify(c *yyds.CS, i any) []error {
	return nil
}
